* FIGURE 1: PLOT GRAPHS OF STATUTORY TAX RATES


version 13.1
clear
cap clear matrix
cap log close
set more off
set scheme mygraphs


cd "$mypathRR/Datasets/"

* *******************************************************************************
* FIND THE CROSSING POINTS OF AVGT IN 2006 AND 2008 FOREACH TYPE IN EACH MUNICIPALITY
use "marg+avg_taxrates_OW_1995-2010+multipliers.dta", clear

foreach type in 2 4 0 {
forvalues n=1401(1)1407 {

preserve
drop if year<2006
drop if year==2007
drop if year>2008
keep if snpzivcd==`type'
keep year snpzivcd gross_inc snpsteink avgt_tx_`n' 
sort gross_inc year 

rename avgt_tx_`n' avgt_`n'_tx

reshape wide avgt_`n'_tx, i(gross_inc) j(year)

gen diff=avgt_`n'_tx2006-avgt_`n'_tx2008
egen min=min( diff)
gen diff_sign=sign(diff)
gen switch=(diff_sign[_n]!=diff_sign[_n-1])
replace switch=0 if diff_sign==0

gen gde=`n'
mkmat gross_inc diff_sig snpzivcd gde snpsteink if switch==1, matrix(A)
matrix list A
svmat A

tempfile mydata
save "`mydata'"

keep A*
rename A1 gross_inc
rename A2 diff_2006_2008
label var diff_2006_2008 "-1: tax in 2008 higher"
rename A3 snpzivcd
rename A4 gde
rename A5 snpsteink
drop if snpsteink==.
save "taxable_xing_zivcd`type'_gde`n'.dta", replace

use "`mydata'", clear
drop switch

reshape long avgt_`n'_tx,  i(gross_inc) j(year2)
restore
}
}

use "taxable_xing_zivcd0_gde1401.dta", clear
drop if gross_inc>=0

foreach type in 2 4 0 {
forvalues n=1401(1)1407 {
append using "taxable_xing_zivcd`type'_gde`n'.dta"
}
}

bys snpzivcd gde: egen cross=max(snpsteink)
gen cross_max=(cross==snpsteink)
sort snpzivcd gde snpsteink
save "taxable_xing_2006_2008_all.dta", replace

foreach type in 2 4 0 {
forvalues n=1401(1)1407 {
erase "taxable_xing_zivcd`type'_gde`n'.dta"
}
}


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
* Save locals to display crossing of 2006 and 2008 schedule at the top
use "taxable_xing_2006_2008_all.dta", clear

forvalues n=1401(1)1407 {

  sum snpsteink if cross_max==1 & gde==`n' & snpzivcd==2
  display %12.0fc 
  local crossing_`n'_2 : display %-12.0fc  `r(mean)'
  display `crossing_`n'_2'
  
  sum snpsteink if cross_max==1 & gde==`n' & snpzivcd==4
  local crossing_`n'_4 : display %-12.0fc `r(mean)'
  display `crossing_`n'_4'

  sum snpsteink if cross_max==1 & gde==`n' & snpzivcd==0
  local crossing_`n'_0 : display %-12.0fc  `r(mean)'
  display `crossing_`n'_0'
}

// display the municipality names nicely
	local 1401 "Alpnach"
	local 1402 "Engelberg"
	local 1403 "Giswil"
	local 1404 "Kerns"
	local 1405 "Lungern"
	local 1406 "Sachseln"
	local 1407 "Sarnen"
	

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

* MAKE THE GRPAHS


use "marg+avg_taxrates_OW_1995-2010+multipliers.dta", clear

cd "$mypathRR/Results"

forvalues n=1407(1)1407 { // to run for all municipalities: n=1401(1)1407, but then change range of y-axis from 0.21 to 0.25
	replace avgt_tx_`n' = 0 if avgt_tx_`n'  == . 
	replace sb`n' = 0 if einfachSteuer  == 0


* 1.  MARRIED NO KIDS
 preserve

 keep if snpzivcd==2 /*keeps the married only MAWONOKS*/
 replace snpsteink= snpsteink/1000 /*express taxable income in 1000 francs*/
 sort year snpsteink

	// AVERAGE TAX RATES
	local iffs "snpsteink>=1 & snpsteink<=700"
	mylabels 0(2)21, myscale(@/100) suffix(" %") local(myla)
	graph twoway (line avgt_tx_`n' snpsteink if `iffs' & year==1995, lwidth(thick) lcolor("0 255 255")) || ///
	(line avgt_tx_`n' snpsteink if `iffs' & year==2001, lwidth(thick) lcolor("50 280 50")) || ///
	(line avgt_tx_`n' snpsteink if `iffs' & year==2003, lwidth(thick) lcolor("0 0 153")) || ///
	(line avgt_tx_`n' snpsteink if `iffs' & year==2006, lwidth(thick) lcolor("205 92 92")) || ///
	(line avgt_tx_`n' snpsteink if `iffs' & year==2008, lwidth(thick) lcolor("50 205 50" )), ///
	  /*by(fid2, ixaxes note(""))*/ ytitle("Average tax rates in ``n''" "(in % of taxable income)") xtitle(Taxable income (in 1000 CHF)) ///
	   xlabel(0[35]700, ang(45))  yla(`myla', ang(h)) ///
	  legend(label(1 "1995/96") label(2 "2001") label(3 "2003") label(4 "2006") label(5 "2008") rows(1)  symxsize(9) symysize(0.5) size(3)  keygap(1) lwidth(vvthin)) ///
	  note("2006 and 2008 schedules cross at CHF `crossing_`n'_2'")  
  
  
	// MARGINAL TAX RATES
	local iffs "sb`n'<=0.21 & snpsteink>=1 & snpsteink<=700"
	mylabels 0(2)21, myscale(@/100) suffix(" %") local(myla)
	graph twoway (line sb`n' snpsteink if `iffs' & year==1995, lwidth(thick) lcolor("0 255 255")) || ///
	(line sb`n' snpsteink if `iffs' & year==2001, lwidth(thick) lcolor("50 280 50")) || ///
	(line sb`n' snpsteink if `iffs' & year==2003, lwidth(thick) lcolor("0 0 153")) || ///
	(line sb`n' snpsteink if `iffs' & year==2006, lwidth(thick) lcolor("205 92 92")) || ///
	(line sb`n' snpsteink if `iffs' & year==2008, lwidth(thick) lcolor("50 205 50" )), ///
	  /*by(fid2, ixaxes note(""))*/ ytitle("Marginal tax rates in ``n''" "(in % of taxable income)") xtitle(Taxable income (in 1000 CHF)) ///
	   xlabel(0[35]700, ang(45))  yla(`myla', ang(h)) ymtick(0(.01).20, grid)   ///
	  legend(label(1 "1995/96") label(2 "2001") label(3 "2003") label(4 "2006") label(5 "2008") rows(1)  symxsize(9) symysize(0.5) size(3)  keygap(1) lwidth(vvthin))   
	  
 restore
 
  

*   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *

* 2.  MARRIED WITH KIDS
 preserve
 
 keep if gdekannr==6 /*keeps OW only */
 keep if snpzivcd==4/*keeps the married with kids only MAWOKIDS*/
 replace snpsteink= snpsteink/1000 /*express taxable income in 1000 francs*/
 sort year snpsteink

	// AVERAGE TAX RATES
	local iffs "avgt_tx_`n'<=0.21 & snpsteink>=1 & snpsteink<=700"
	mylabels 0(2)21, myscale(@/100) suffix(" %") local(myla)
	graph twoway (line avgt_tx_`n' snpsteink if `iffs' & year==1995, lwidth(thick) lcolor("0 255 255")) || ///
	(line avgt_tx_`n' snpsteink if `iffs' & year==2001, lwidth(thick) lcolor("50 280 50")) || ///
	(line avgt_tx_`n' snpsteink if `iffs' & year==2003, lwidth(thick) lcolor("0 0 153")) || ///
	(line avgt_tx_`n' snpsteink if `iffs' & year==2006, lwidth(thick) lcolor("205 92 92")) || ///
	(line avgt_tx_`n' snpsteink if `iffs' & year==2008, lwidth(thick) lcolor("50 205 50" )), ///
	  /*by(fid2, ixaxes note(""))*/ ytitle("Average tax rates in ``n''" "(in % of taxable income)") xtitle(Taxable income (in 1000 CHF)) ///
	   xlabel(0[35]700, ang(45))  yla(`myla', ang(h))  ///
	  legend(label(1 "1995/96") label(2 "2001") label(3 "2003") label(4 "2006") label(5 "2008") rows(1)  symxsize(9) symysize(0.5) size(3)  keygap(1) lwidth(vvthin)) ///
	  note("2006 and 2008 schedules cross at CHF `crossing_`n'_4'")	  
	  
	// MARGINAL TAX RATES
	local iffs "sb`n'<=0.21 & snpsteink>=1 & snpsteink<=700"
	mylabels 0(2)21, myscale(@/100) suffix(" %") local(myla)
	graph twoway (line sb`n' snpsteink if `iffs' & year==1995, lwidth(thick) lcolor("0 255 255")) || ///
	(line sb`n' snpsteink if `iffs' & year==2001, lwidth(thick) lcolor("50 280 50")) || ///
	(line sb`n' snpsteink if `iffs' & year==2003, lwidth(thick) lcolor("0 0 153")) || ///
	(line sb`n' snpsteink if `iffs' & year==2006, lwidth(thick) lcolor("205 92 92")) || ///
	(line sb`n' snpsteink if `iffs' & year==2008, lwidth(thick) lcolor("50 205 50" )), ///
	  /*by(fid2, ixaxes note(""))*/ ytitle("Marginal tax rates in ``n''" "(in % of taxable income)") xtitle(Taxable income (in 1000 CHF)) ///
	   xlabel(0[35]700, ang(45))  yla(`myla', ang(h)) ymtick(0(.01).20, grid)   ///
	  legend(label(1 "1995/96") label(2 "2001") label(3 "2003") label(4 "2006") label(5 "2008") rows(1)  symxsize(9) symysize(0.5) size(3)  keygap(1) lwidth(vvthin))   
	
 restore
 
  

*   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *

* 3.  SINGLE, NO KIDS
 preserve

 keep if gdekannr==6 /*keeps OW only */
 keep if snpzivcd==0 /*keeps the only the SINGLE*/
 replace snpsteink= snpsteink/1000 /*express taxable income in 1000 francs*/
 sort year snpsteink

	// AVERAGE TAX RATES
	local iffs "avgt_tx_`n'<=0.21 & snpsteink>=0 & snpsteink<=700"
	mylabels 0(2)21, myscale(@/100) suffix(" %") local(myla)
	graph twoway (line avgt_tx_`n' snpsteink if `iffs' & year==1995, lwidth(thick) lcolor("0 255 255")) || ///
	(line avgt_tx_`n' snpsteink if `iffs' & year==2001, lwidth(thick) lcolor("50 280 50")) || ///
	(line avgt_tx_`n' snpsteink if `iffs' & year==2003, lwidth(thick) lcolor("0 0 153")) || ///
	(line avgt_tx_`n' snpsteink if `iffs' & year==2006, lwidth(thick) lcolor("205 92 92")) || ///
	(line avgt_tx_`n' snpsteink if `iffs' & year==2008, lwidth(thick) lcolor("50 205 50" )), ///
	  /*by(fid2, ixaxes note(""))*/ ytitle("Average tax rates in ``n''" "(in % of taxable income)") xtitle(Taxable income (in 1000 CHF)) ///
	   xlabel(0[35]700, ang(45))  yla(`myla', ang(h)) ymtick(0(.01).20, grid) ///
	  legend(label(1 "1995/96") label(2 "2001") label(3 "2003") label(4 "2006") label(5 "2008") rows(1)  symxsize(9) symysize(0.5) size(3)  keygap(1) lwidth(vvthin)) ///
	  note("2006 and 2008 schedules cross at CHF `crossing_`n'_0'")
	 
		graph export "Fig_1c)-OW_avgtax_`n'_SINGLE.pdf", as(pdf)  replace
	  
	  
	// MARGINAL TAX RATES
	local iffs "sb`n'<=0.21 & snpsteink>=1 & snpsteink<=700"
	mylabels 0(2)21, myscale(@/100) suffix(" %") local(myla)
	graph twoway (line sb`n' snpsteink if `iffs' & year==1995, lwidth(thick) lcolor("0 255 255")) || ///
	(line sb`n' snpsteink if `iffs' & year==2001, lwidth(thick) lcolor("50 280 50")) || ///
	(line sb`n' snpsteink if `iffs' & year==2003, lwidth(thick) lcolor("0 0 153")) || ///
	(line sb`n' snpsteink if `iffs' & year==2006, lwidth(thick) lcolor("205 92 92")) || ///
	(line sb`n' snpsteink if `iffs' & year==2008, lwidth(thick) lcolor("50 205 50" )), ///
	  /*by(fid2, ixaxes note(""))*/ ytitle("Marginal tax rates in ``n''" "(in % of taxable income)") xtitle(Taxable income (in 1000 CHF)) ///
	   xlabel(0[35]700, ang(45))  yla(`myla', ang(h)) ymtick(0(.01).20, grid)   ///
	  legend(label(1 "1995/96") label(2 "2001") label(3 "2003") label(4 "2006") label(5 "2008") rows(1)  symxsize(9) symysize(0.5) size(3)  keygap(1) lwidth(vvthin))   
	  
		graph export "Fig_1a)-OW_margtax_`n'_SINGLE.pdf", as(pdf)  replace

 restore 
}


********************************************************************************
********************************************************************************

* WEALTH TAX RATES *

cd "$mypathRR/Datasets/"
use "marg+avg_wealth_taxrates_OW_1995-2010+multipliers.dta", clear

cd "$mypathRR/Results"

* Display the municipality names nicely
local 1401 "Alpnach"
local 1402 "Engelberg"
local 1403 "Giswil"
local 1404 "Kerns"
local 1405 "Lungern"
local 1406 "Sachseln"
local 1407 "Sarnen"


forvalues n=1407(1)1407 { // to run for all municipalities: n=1401(1)1407

* 1. MARRIED NO KIDS, NO KIDS
 preserve
 
 keep if gdekannr==6 /*keeps OW only */
 keep if snpzivcd==2 /*keeps the married only MAWONOKS*/
 replace reinverm= reinverm/1000000 /*express taxable wealth in million francs*/
 sort year reinverm

	// AVG WEALTH TAX
	local iffs "avgwt_gr_`n'<=0.25 & reinverm>=0.01 & reinverm<=6"
	mylabels 0(0.05)0.45, myscale(@/100) suffix(" %") local(myla)
	graph twoway (line avgwt_gr_`n' reinverm if `iffs' & year==1995, lwidth(thick) lcolor("0 255 255")) || ///
	(line avgwt_gr_`n' reinverm if `iffs' & year==2001, lwidth(thick) lcolor("50 280 50")) || ///
	(line avgwt_gr_`n' reinverm if `iffs' & year==2003, lwidth(thick) lcolor("0 0 153")) || ///
	(line avgwt_gr_`n' reinverm if `iffs' & year==2006, lwidth(thick) lcolor("205 92 92")) || ///
	(line avgwt_gr_`n' reinverm if `iffs' & year==2008, lwidth(thick) lcolor("50 205 50" )), ///
	  /*by(fid2, ixaxes note(""))*/ ytitle("Average tax rates in ``n''" "(in % of net wealth)") xtitle("Net wealth (in mio CHF)") ///
	   xlabel(0[0.5]6, ang(45))  yla(`myla', ang(h))  ///
	  legend(label(1 "1995/96") label(2 "2001") label(3 "2003") label(4 "2006") label(5 "2008") rows(1)  symxsize(9) symysize(0.5) size(3)  keygap(1) lwidth(vvthin)) 


	// MARG WEALTH TAX
	local iffs "sbw`n'<=0.25 & reinverm>=0.001 & reinverm<=6"
	mylabels 0(0.05)0.45, myscale(@/100) suffix(" %") local(myla)
	graph twoway (line sbw`n' reinverm if `iffs' & year==1995, lwidth(thick) lcolor("0 255 255")) || ///
	(line sbw`n' reinverm if `iffs' & year==2001, lwidth(thick) lcolor("50 280 50")) || ///
	(line sbw`n' reinverm if `iffs' & year==2003, lwidth(thick) lcolor("0 0 153")) || ///
	(line sbw`n' reinverm if `iffs' & year==2006, lwidth(thick) lcolor("205 92 92")) || ///
	(line sbw`n' reinverm if `iffs' & year==2008, lwidth(thick) lcolor("50 205 50" )), ///
	  /*by(fid2, ixaxes note(""))*/ ytitle("Marginal tax rates in ``n''" "(in % of net wealth)") xtitle("Net wealth (in mio CHF)") ///
	   xlabel(0[0.5]6, ang(45))  yla(`myla', ang(h))  ///
	  legend(label(1 "1995/96") label(2 "2001") label(3 "2003") label(4 "2006") label(5 "2008") rows(1)  symxsize(9) symysize(0.5) size(3)  keygap(1) lwidth(vvthin))   

 restore
 
 
*   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *

* 2. SINGLE, NO KIDS, AVG WEALTH TAX

 preserve
 keep if gdekannr==6 /*keeps OW only */
 keep if snpzivcd==0 /*keeps only the SINGLE*/
 replace reinverm= reinverm/1000000 /*express taxable wealth in million francs*/
 sort year reinverm

	// AVG WEALTH TAX
	local iffs "avgwt_gr_`n'<=0.25 & reinverm>=0.01 & reinverm<=6"
	mylabels 0(0.05)0.45, myscale(@/100) suffix(" %") local(myla)
	graph twoway (line avgwt_gr_`n' reinverm if `iffs' & year==1995, lwidth(thick) lcolor("0 255 255")) || ///
	(line avgwt_gr_`n' reinverm if `iffs' & year==2001, lwidth(thick) lcolor("50 280 50")) || ///
	(line avgwt_gr_`n' reinverm if `iffs' & year==2003, lwidth(thick) lcolor("0 0 153")) || ///
	(line avgwt_gr_`n' reinverm if `iffs' & year==2006, lwidth(thick) lcolor("205 92 92")) || ///
	(line avgwt_gr_`n' reinverm if `iffs' & year==2008, lwidth(thick) lcolor("50 205 50" )), ///
	  /*by(fid2, ixaxes note(""))*/ ytitle("Average tax rates in ``n''" "(in % of net wealth)") xtitle("Net wealth (in mio CHF)") ///
	   xlabel(0[0.5]6, ang(45))  yla(`myla', ang(h))  ///
	  legend(label(1 "1995/96") label(2 "2001") label(3 "2003") label(4 "2006") label(5 "2008") rows(1)  symxsize(9) symysize(0.5) size(3)  keygap(1) lwidth(vvthin)) 
	 
		graph export "Fig_1d)-OW_avgtax_wea_`n'_SINGLE.pdf", as(pdf)  replace



	// MARG WEALTH TAX
	local iffs "sbw`n'<=0.25 & reinverm>=0.001 & reinverm<=6"
	mylabels 0(0.05)0.45, myscale(@/100) suffix(" %") local(myla)
	graph twoway (line sbw`n' reinverm if `iffs' & year==1995, lwidth(thick) lcolor("0 255 255")) || ///
	(line sbw`n' reinverm if `iffs' & year==2001, lwidth(thick) lcolor("50 280 50")) || ///
	(line sbw`n' reinverm if `iffs' & year==2003, lwidth(thick) lcolor("0 0 153")) || ///
	(line sbw`n' reinverm if `iffs' & year==2006, lwidth(thick) lcolor("205 92 92")) || ///
	(line sbw`n' reinverm if `iffs' & year==2008, lwidth(thick) lcolor("50 205 50" )), ///
	  /*by(fid2, ixaxes note(""))*/ ytitle("Marginal tax rates in ``n''" "(in % of net wealth)") xtitle("Net wealth (in mio CHF)") ///
	   xlabel(0[0.5]6, ang(45))  yla(`myla', ang(h))  ///
	  legend(label(1 "1995/96") label(2 "2001") label(3 "2003") label(4 "2006") label(5 "2008") rows(1)  symxsize(9) symysize(0.5) size(3)  keygap(1) lwidth(vvthin))   

		graph export "Fig_1b)-OW_margtax_wea_`n'_SINGLE.pdf", as(pdf)  replace

restore

}


rm "$mypathRR/Datasets/taxable_xing_2006_2008_all.dta"


								* * * * *  E N D  * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

